package com.blog.backend.controller;


import com.blog.backend.annotation.LoginAnno;
import com.blog.backend.req.AddAlbumReq;
import com.blog.backend.req.PageAlbumReq;
import com.blog.backend.resp.BlogAlbumResp;
import com.blog.backend.service.BlogAlbumService;
import com.blog.backend.utils.Result;
import com.blog.backend.vo.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/album")
public class BlogAlbumController {

    @Resource
    private BlogAlbumService blogAlbumService;

    @PostMapping("/addAlbum")
    @LoginAnno
    @ApiOperation("新增相册")
    public Result<Boolean> addAlbum(@RequestBody AddAlbumReq req){
       Boolean result = blogAlbumService.insertAlbum(req);
       return  Result.success(result);
    }

    @PostMapping("/selectPageAlbum")
    @LoginAnno
    @ApiOperation("查询相册列表")
    public Result<PageResult<BlogAlbumResp>> selectPageAlbum(@RequestBody PageAlbumReq req){
        PageResult<BlogAlbumResp> result=  blogAlbumService.selectPageAlbum(req);
        return Result.success(result);
    }

    @GetMapping("/selectAlbumDetail")
    @LoginAnno
    @ApiOperation("查看详情")
    public Result<BlogAlbumResp> selectAlbumDetail(@RequestParam String albumId){
        BlogAlbumResp resp=blogAlbumService.selectAlbumDetail(albumId);
        return Result.success(resp);
    }

    @PostMapping("/updateAlbumDetail")
    @LoginAnno
    @ApiOperation("修改详情")
    public Result<Boolean> updateAlbumDetail(@RequestBody AddAlbumReq req){
        Boolean result=blogAlbumService.updateAlbumDetail(req);
        return Result.success(result);
    }

    @GetMapping("/deleteAlbum")
    @LoginAnno
    @ApiOperation("删除相册")
    public Result<Boolean> deleteAlbum(@RequestParam String albumId){
        Boolean result= blogAlbumService.deleteAlbum(albumId);
        return  Result.success(result);
    }
}
